﻿using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Utilities.Encoders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Encalgorithm
{
    public  class SM3Utils
    {

        public static string Hash(string str)
        {
            SM3Digest sm3 = new SM3Digest();
            byte[] md = new byte[sm3.GetDigestSize()];
            byte[] msg1 = Encoding.UTF8.GetBytes(str);
            sm3.BlockUpdate(msg1, 0, msg1.Length);
            sm3.DoFinal(md, 0);
            string s = Encoding.UTF8.GetString(Hex.Encode(md));
            return s.ToUpper();
        }

        public static byte[] Hash(byte[] value)
        {
            SM3Digest sm3 = new SM3Digest();
            byte[] md = new byte[sm3.GetDigestSize()];
            sm3.BlockUpdate(value, 0, value.Length);
            sm3.DoFinal(md, 0);
            return md;
        }
    }
}
